//
//  FoodNameViewController.m
//  FoodCorner
//
//  Created by Summer on 16/3/11.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "FoodNameViewController.h"
#import "AddFoodListViewController.h"
#define kMyColorRGB [UIColor colorWithRed: (CGFloat) 225/255.0  green: (CGFloat) 66/255.0  blue: (CGFloat) 88/255.0  alpha: (CGFloat) 0.1];
@interface FoodNameViewController ()
@property (nonatomic,strong) UITextField *foodNameTF;
@end

@implementation FoodNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"创建菜谱";
    
    self.view.backgroundColor = kMyColorRGB;
    // Do any additional setup after loading the view.
    self.foodNameTF = [[UITextField alloc]initWithFrame:CGRectMake(60, 150, 260, 30)];
    self.foodNameTF.placeholder = @"例如：清炒小白菜（简约版）";
    UILabel *infoLab = [[UILabel alloc]initWithFrame:CGRectMake(90, 200, 200, 30)];
    infoLab.text = @"创建菜谱的人是厨房的天使";
    infoLab.font = [UIFont systemFontOfSize:16];
    infoLab.textColor = [UIColor grayColor];
    infoLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:infoLab];
    self.foodNameTF.borderStyle = UITextBorderStyleRoundedRect;
    self.foodNameTF.layer.masksToBounds = YES;
    self.foodNameTF.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor blackColor]);
    [self.view addSubview:self.foodNameTF];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:(UIBarButtonSystemItemStop)  target:self action:@selector(clickBackButtonAciotn)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"下一步" style:(UIBarButtonItemStylePlain) target:self action:@selector(foodCookListAction)];
    
    
}
- (void)clickBackButtonAciotn
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)foodCookListAction
{
    if (self.foodNameTF.text.length != 0) {
        
        AddFoodListViewController *addFoodVC = [[AddFoodListViewController alloc]init];
        addFoodVC.title = self.foodNameTF.text;
        [self.navigationController pushViewController:addFoodVC animated:YES];
        
    }else
    {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"菜品名称不能为空" preferredStyle:(UIAlertControllerStyleAlert)];
        
        [self presentViewController:alert animated:YES completion:nil];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self dismissViewControllerAnimated:YES completion:nil];
        });
    }
}

@end
